﻿using System;

namespace 工厂方法模式
{
    class Program
    {


        /*
         * 
         * 
         */
        static void Main(string[] args)
        {
            IFactory factory = new realizeOneFactory();
            var realizeOne = (realizeOne)factory.GetBaseFunction();
            realizeOne.sweep();
            realizeOne.buyRice();

            IFactory factoryTwo = new realizeTwoFactory();
            var realizeTwo = (realizeTwo)factoryTwo.GetBaseFunction();
            realizeTwo.sweep();
            realizeTwo.read();
            realizeTwo.buyRice();

        }


        /// <summary>
        /// 基础类
        /// </summary>
        class BaseFunction
        {
            public void sweep()
            {
                Console.WriteLine("扫地");
            }

            public void wash()
            {
                Console.WriteLine("洗衣服");
            }
            public void buyRice()
            {
                Console.WriteLine("买米");
            }
        }

        /// <summary>
        /// 实现类1
        /// </summary>
        class realizeOne : BaseFunction 
        {
         public void write()
            {
                Console.WriteLine("写信");
            }
        }
        /// <summary>
        /// 实现类2
        /// </summary>
        class realizeTwo : BaseFunction
        { 
            public  void read()
            {
                Console.WriteLine("读书");
            }
        }

        /// <summary>
        /// 基础工厂
        /// </summary>
        interface IFactory
        {
            BaseFunction GetBaseFunction();
        }

        /// <summary>
        /// 实现1 的工厂方法
        /// </summary>
        class realizeOneFactory : IFactory
        {
            public BaseFunction GetBaseFunction()
            {
                return new realizeOne();
            }
        }

        class realizeTwoFactory : IFactory
        {
            public BaseFunction GetBaseFunction()
            {
                return new realizeTwo();
        }
    }

    }
}
